package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.VideoVo;
import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Classname VideoController
 * @Description TODO 视频web
 * @Date 2021/3/15 15:11
 * @Created by gan
 */
@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;
    //发布小视频
    @PostMapping
    public ResponseEntity post(MultipartFile videoThumbnail,
                               MultipartFile videoFile)throws IOException {
        videoService.post(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

    //小视频列表（分页查询）
    @GetMapping
    public ResponseEntity findPage(@RequestParam(defaultValue = "1")Long page,
                                   @RequestParam(defaultValue = "10")Long pagesize){
        page=page<1?1:page;
        PageResult<VideoVo> pageResult=videoService.findPage(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    //关注视频(关注视频作者)
    @PostMapping("/{id}/userFocus")
    public ResponseEntity followUser(@PathVariable("id")long userId){
        videoService.followUser(userId);
        return ResponseEntity.ok(null);
    }

    //取消关注
    @PostMapping("/{id}/userUnFocus")
    public ResponseEntity unfollowUser(@PathVariable("id") long userId){
        videoService.unfollowUser(userId);
        return ResponseEntity.ok(null);
    }
}
